//
//  ZYCTeaLeaveRecordRootCell.m
//  ZDSC
//
//  Created by 张威 on 2021/11/9.
//

#import "ZYCTeaLeaveRecordRootCell.h"
#import "ZYCTeaLeaveRecordRootModel.h"
@interface ZYCTeaLeaveRecordRootCell ()

@property (nonatomic, strong) UIView *bgWhiteView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *startTimeLabel;
@property (nonatomic, strong) UILabel *endTimeLabel;
@property (nonatomic, strong) UILabel *typeLabel;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UIButton *revokeButton;

@end
@implementation ZYCTeaLeaveRecordRootCell

// 审批状态（1：审批中；2：驳回；3：通过；4：撤销）
- (void)setModel:(ZYCTeaLeaveRecordRootModel *)model{
    _model = model;
    _titleLabel.text = model.leaveTitle;
    _dateLabel.text = model.createTime;
    if (self.type == ZYCTeaLeaveRecordRootCellTypeSend) {
        if ([model.status integerValue] == 4) {
            self.revokeButton.hidden = YES;
        }else{
            self.revokeButton.hidden = NO;
        }
    }else{
        self.revokeButton.hidden = YES;
    }
    _startTimeLabel.text = [NSString stringWithFormat:@"开始时间: %@",model.leaveStartTime];
    _endTimeLabel.text = [NSString stringWithFormat:@"结束时间: %@",model.leaveEndTime];
    _typeLabel.text = [NSString stringWithFormat:@"请假类型: %@",model.leaveTypeName];
    if ([model.status integerValue] == 1) {
        _statusLabel.textColor = HEX_RGB(@"#EEA92D");
    }else if([model.status integerValue] == 2){
        _statusLabel.textColor = HEX_RGB(@"#E93C06");
    }else if([model.status integerValue] == 3){
        _statusLabel.textColor = HEX_RGB(@"#41B166");
    }else{
        _statusLabel.textColor = HEX_RGB(@"#999999");
    }
    _statusLabel.text = model.statusStr;
}



+ (instancetype)TeaLeaveRecordRootCellWithType:(ZYCTeaLeaveRecordRootCellType)type TableView:(UITableView *)tableView{
    static NSString *rid = @"kReuseIdentifier";
    ZYCTeaLeaveRecordRootCell *cell = [tableView dequeueReusableCellWithIdentifier:rid];
    if (!cell) {
        cell = [[ZYCTeaLeaveRecordRootCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:rid];
        cell.type = type;
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgWhiteView];
        [self.bgWhiteView addSubview:self.titleLabel];
        [self.bgWhiteView addSubview:self.dateLabel];
        [self.bgWhiteView addSubview:self.line];
        [self.bgWhiteView addSubview:self.startTimeLabel];
        [self.bgWhiteView addSubview:self.endTimeLabel];
        [self.bgWhiteView addSubview:self.typeLabel];
        [self.bgWhiteView addSubview:self.revokeButton];
        [self.bgWhiteView addSubview:self.statusLabel];

        
        [self.bgWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(9.5f);
            make.right.equalTo(self.contentView).offset(-9.5f);
            make.top.bottom.equalTo(self.contentView);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.mas_lessThanOrEqualTo(self.dateLabel.mas_left).offset(-5.0f);
            make.top.equalTo(self.bgWhiteView).offset(10.0f);
        }];
        
        [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgWhiteView).offset(-10.0f);
            make.centerY.equalTo(self.titleLabel);
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(17.5f);
            make.height.mas_equalTo(1.0f);
        }];
        
        
        [self.startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.line.mas_bottom).offset(17.5f);
        }];
        
        [self.endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.startTimeLabel.mas_bottom).offset(15.0f);
        }];
        
        [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.endTimeLabel.mas_bottom).offset(15.0f);
            make.bottom.equalTo(self.bgWhiteView).offset(-10.5f);
        }];
        
        [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.top.equalTo(self.line.mas_bottom).offset(10.0f);
        }];
        
        [self.revokeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.top.equalTo(self.statusLabel.mas_bottom).offset(10.0f);
            make.width.mas_equalTo(57.0f);
            make.height.mas_equalTo(24.0f);
        }];
        
        
        [self.dateLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    }
    return self;
}

- (UIView *)bgWhiteView {
    if (!_bgWhiteView) {
        _bgWhiteView = [[UIView alloc] init];
        _bgWhiteView.backgroundColor = HEX_RGB(@"#FFFFFF");
        _bgWhiteView.layer.cornerRadius = 7.5;
        _bgWhiteView.layer.masksToBounds = YES;
    }
    return _bgWhiteView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17) titleColor:HEX_RGB(kTitleThemeColor) textAlignment:ZZTextAlignmentLeft];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#939393") textAlignment:ZZTextAlignmentLeft];
    }
    return _dateLabel;
}

- (UILabel *)startTimeLabel {
    if (!_startTimeLabel) {
        _startTimeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#939393") textAlignment:ZZTextAlignmentLeft];
    }
    return _startTimeLabel;
}
- (UILabel *)endTimeLabel {
    if (!_endTimeLabel) {
        _endTimeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#939393") textAlignment:ZZTextAlignmentLeft];
    }
    return _endTimeLabel;
}

- (UILabel *)typeLabel {
    if (!_typeLabel) {
        _typeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#939393") textAlignment:ZZTextAlignmentLeft];
    }
    return _typeLabel;
}

- (UIButton *)revokeButton {
    if (!_revokeButton) {
        _revokeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _revokeButton.layer.borderWidth = 1.0f;
        _revokeButton.layer.borderColor = HEX_RGB(@"#999999").CGColor;
        _revokeButton.layer.cornerRadius = 11.5;
        _revokeButton.layer.masksToBounds = YES;
        [_revokeButton setTitle:@"撤销" forState:UIControlStateNormal];
        [_revokeButton setTitleColor:HEX_RGB(@"999999") forState:UIControlStateNormal];
        _revokeButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 14);
        _revokeButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [_revokeButton addTarget:self action:@selector(clickRevoke:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _revokeButton;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc] init];
        _statusLabel.font = kCustomFont(@"PingFangSC-Regular", 14);
        _statusLabel.textAlignment = NSTextAlignmentRight;
    }
    return _statusLabel;
}


- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}

- (void)clickRevoke:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(teaLeaveRecordRootCellDidRevoke:)]) {
        [self.delegate teaLeaveRecordRootCellDidRevoke:self.model.teacherLeaveId];
    }
}
@end
